# delimit ;
clear all;
***************************************************************************************;
*infile children's data (assesment data), all years 1986-2012, accessed March 14, 2015;
***************************************************************************************;

local do_here = 1;
if `do_here' == 1 {;
cd "$nlsy_data_dir";
infile using nlsy_raw1.dct, clear;
*compress;
do raw1_labels.do;
tolower;
cd "$scratch_dir";
save temp_nlsy_ass.dta, replace;

cd "$nlsy_data_dir";
infile using YA_income.dct, clear;
*compress;
do YA_Income-value-labels.do;
tolower;

cd "$scratch_dir";
merge using temp_nlsy_ass.dta;
drop _merge;
cd "$scratch_dir";
save temp_nlsy_assessment.dta, replace;
};



***************************************************************************************;
*infile children's data (mother supplement), all years 1986-2012, accessed March 15, 2015;
***************************************************************************************;

local do_here = 1;
if `do_here' == 1 {;

cd "$nlsy_data_dir";
infile using mother_supplement.dct, clear;
*compress;
do mother_supplement_labels.do, nostop;
tolower;
cd "$scratch_dir";
save temp1_nlsy_mother.dta, replace;

cd "$nlsy_data_dir";
infile using Natal.dct, clear;
*compress;
do Natal-value-labels.do, nostop;
tolower;
rename pst0002_xrnd gest_length;
rename  pst0009_xrnd weight_atbirth;


cd "$scratch_dir";
merge using temp1_nlsy_mother.dta; 
drop _merge;
save temp2_nlsy_mother.dta, replace;

cd "$nlsy_data_dir";
infile using YA_common.dct, clear;
*compress;

do YA_common-value-labels.do, nostop;
tolower;

* y1211300 is the latest information about the highest grade 
* received by the child/young-adult in the nlsy79 child/young adult
* in the YA COMMON KEY VARIABLES Area of interest.
;




rename y1211300 education;
replace education=-7 if education==95;




cd "$scratch_dir";
merge using temp2_nlsy_mother.dta; 
drop _merge;
save temp_nlsy_mother.dta, replace;

};



***************************************************************************************;
*infile original nlsy79 data (on mother)
***************************************************************************************;

local do_here = 1;
if `do_here' == 1 {;

*
some basic files (education, wages, income information)
--accessed March 17, 2005
;
cd "$nlsy_data_dir";
infile using nlsy79.dct, clear;
do nlsy79_labels.do, nostop;
tolower;

sort caseid_1979;
cd "$scratch_dir";
save temp.dta, replace;

*
demographics file--accessed June 14, 2015
--includes: 
marriage, fertility, context, geography, and survey (weights) variables
;
cd "$nlsy_data_dir";
infile using nlsy79_demographics.dct, clear;
do nlsy79_demographics_labels.do, nostop;
tolower;
sort caseid_1979;

*merge by nlsy79 id;
cd "$scratch_dir";
merge caseid_1979 using temp.dta;
tab _merge;
drop _merge;
sort caseid_1979;
save temp.dta, replace;

*
household, context, geography file (overlaps some with demographics file)
--accessed June 14, 2015
;
cd "$nlsy_data_dir";
infile using nlsy79_household.dct, clear;
do nlsy79_household_labels.do, nostop;
tolower;
sort caseid_1979;

*merge by nlsy79 id;
cd "$scratch_dir";
merge caseid_1979 using temp.dta;
tab _merge;
drop _merge;
sort caseid_1979;
save temp.dta, replace;


*
children file
--accessed June 14, 2015
;
cd "$nlsy_data_dir";
infile using nlsy79_children.dct, clear;
do nlsy79_children_labels.do, nostop;
tolower;
sort caseid_1979;

*merge by nlsy79 id;
cd "$scratch_dir";
merge caseid_1979 using temp.dta;
tab _merge;
drop _merge;


*compress;
cd "$scratch_dir";
save temp_nlsy79.dta, replace;

};





***************************************************************************************;
*merge data and create combined dataset
***************************************************************************************;
*https://www.nlsinfo.org/content/getting-started/intro-to-the-nls/tutorials/tutorial-linking-nlsy79-mothers-and-their;

*ids:
*cpubid_xrnd child id in cnlsy79
*mpubid_xrnd mom id in cnlsy79
*caseid_1979 mom id in original nlsy 79;
;

***************************************************************************************;

************************;
*merge data by mother 
*(nlsy79 original data to mother level data in cnlsy79);
************************;

cd "$scratch_dir";
use temp_nlsy79.dta, clear;
rename caseid_1979 mpubid_xrnd;
sort mpubid_xrnd;

merge 1:n mpubid_xrnd using temp_nlsy_assessment.dta;
tab _merge;
drop _merge;

*drop extra nlsy79 observations (observations without children in cnlsy);
drop if cpubid_xrnd==.;

**************************;
*merge data by child id
*************************;

sort cpubid_xrnd;
cd "$scratch_dir";
save temp1.dta, replace;

cd "$scratch_dir";
use temp_nlsy_mother.dta, clear;
sort cpubid_xrnd;
merge cpubid_xrnd using temp1.dta;

tab _merge;
drop _merge;


***************************;
*add basic variables
***************************;

rename cpubid_xrnd child_id_nlsy;
rename mpubid_xrnd mom_id_nlsy;
rename crace child_race;
rename csex child_sex;
rename cyrb_xrnd child_ybirth;

sort mom_id_nlsy child_ybirth;
bysort mom_id_nlsy: egen child_birth_order = seq();

order child_id_nlsy mom_id_nlsy child_race child_sex child_ybirth child_birth_order;

*compress;
cd "$scratch_dir";
save temp_nlsy_combined.dta, replace;


***************************************************************************************;
*ADDIN CPI INFILE, Accessed April 17, 2015
*http://download.bls.gov/pub/time.series/cu/
***************************************************************************************;

cd "$nlsy_data_dir";
insheet using cpi_formatted.txt, tab clear;
keep if month == "M13"; *annual average;
keep if type == "CUUR0000SA0"; *all items;
keep year value;
rename value cpi_value;
sort year;
compress;

cd "$scratch_dir";
save temp_cpi.dta, replace; 


***************************************************************************************;
*mother's income, and hours
***************************************************************************************;

cd "$scratch_dir";
use temp_nlsy_combined.dta, clear;

*rename hours, income variables;
forvalues j = 1979(1)1994 {;
*local k = `j' - 1;
rename hrswk_pcy_`j' hours`j';
rename q13_5_`j' wage_income`j';
};
forvalues j = 1996(2)2012 {;
rename hrswk_pcy_`j' hours`j';
};
forvalues j = 1996(2)2000 {;
rename q13_5_trunc_revised_`j' wage_income`j';
};
forvalues j = 2002(2)2012 {;
rename q13_5_trunc_`j' wage_income`j';
};

*replace missing codes with dots;
foreach X of varlist hours* wage_income* {;
replace `X' = . if `X' < 0;
};

*create real wages in 2012 dollars;
cd "$scratch_dir";
gen id = 1;
sort id;
save temp.dta, replace;

cd "$scratch_dir";
use temp_cpi.dta, clear;
gen id = 1;
keep if year >= 1978 & year<=2012;

reshape wide cpi_value, i(id) j(year); 
sort id;
merge id using temp.dta;
drop _merge;
local base_year = cpi_value2012;
display `base_year';

forvalues j = 1979(1)1994 {;
*This is because wage_income in each survey is refered to previous calendar year wage income.;
local k = `j' - 1;
gen real_wage_income`j' = wage_income`j' / ( cpi_value`k' / `base_year' );
gen faminc`j'=tnfi_trunc_`j'/(cpi_value`k' / `base_year'); 
};
forvalues j = 1996(2)2012 {;
*This is because wage_income in each survey is refered to previous calendar year wage income.;
local k = `j' - 1;
gen real_wage_income`j' = wage_income`j' / ( cpi_value`k' / `base_year' );
gen faminc`j'=tnfi_trunc_`j'/(cpi_value`k' / `base_year');
};


*create hourly wage;
forvalues j = 1979(1)1994 {;
gen hour_wage`j' = real_wage_income`j' / hours`j';
};
forvalues j = 1996(2)2012 {;
gen hour_wage`j' = real_wage_income`j' / hours`j';
};



*Create wage for Young Adults when they are 29

*age children during the interview;
local age = "y0342400 y0677700 y0974900 y1192500 y1434400 y1672800 
y1948600 y2267200 y2616100 y2966500 ";

local wages = "y0309200 y0610500 y0904800 y1151700 y1386700 y1638400 
y1908700 y2224100 y2573900 y2921600 " ;

local i = 1994;

foreach x in `wages' {;

rename `x' c_wage`i';

local i = `i' + 2;

};

local i = 1994;

foreach x in `age' {;

rename `x' age_child`i';

local i = `i' + 2;

};



forvalues j = 1994(2)2012 {;
*This is because wage_income in each survey is refered to previous calendar year wage income.;
local k = `j' - 1;
gen child_wage`j' = c_wage`j' / ( cpi_value`k' / `base_year' );

};

drop c_wage*;



gen wage_children = .;



forvalues j = 1994(2)2012 {;


replace wage_children = child_wage`j' if age_child`j' == 29;

};

replace education = -7 if age_child2012<23;


drop cpi_value*;
drop age_child*;




***************************************************************************************;
*mother's highest level of schooling
***************************************************************************************;

forvalues j = 1979(1)1994 {;
rename q3_4_`j' mom_school`j';
};
forvalues j = 1996(2)2012 {;
rename q3_4_`j' mom_school`j';
};
*missing values;
forvalues j = 1995(2)2011 {;
gen mom_school`j' = .;
};

foreach X of varlist mom_school* {;
replace `X' = . if `X' < 0; *missing, no response;
replace `X' = . if `X' == 95; *ungraded;
};


*
update mom's latest schooling if missing in this year or lower than previous 
report of schooling
;
gen mom_school_update = mom_school1979;
forvalues j = 1979(1)2012 {;
gen mom_school_old`j' = mom_school`j';
replace mom_school_update = mom_school`j' 
if ( mom_school`j' ~= . & mom_school`j' >= mom_school_update & mom_school_update ~= . )
| ( mom_school_update == . & mom_school`j' ~= . );
replace mom_school`j' = mom_school_update;
};

*check result;
order mom_school_old* mom_school*;
order mom_school_update;

drop mom_school_old* mom_school_update;



***************************************************************************************;
*mother's marital status
***************************************************************************************;

forvalues j = 1979(1)1994 {;
rename marstat_key_`j' mom_marital`j';
};
forvalues j = 1996(2)2012 {;
rename marstat_key_`j' mom_marital`j';
};

*missing values;
forvalues j = 1995(2)2011 {;
gen mom_marital`j'  = .;
};

foreach X of varlist mom_marital* {; 
replace `X' = . if `X' < 0;
};


***************************************************************************************;
*mother's year of birth, age
***************************************************************************************;

rename q1_3_a_y_1979 mom_ybirth;
replace mom_ybirth = mom_ybirth + 1900;

forvalues j = 1979(1)2012 {;
gen mom_age`j' = `j' - mom_ybirth;
};

***************************************************************************************;
*mother's total fertility (as of 2012 interview date)
***************************************************************************************;

*note: this is a sample with at least 1 kid--numbkids_ever > 0;

rename r9908000 numbkids_ever;

*children's date of birth
;
forvalues kid = 1(1)10 {;
rename c`kid'dob_y_xrnd child_ybirth`kid';
replace child_ybirth`kid' = . if child_ybirth`kid' < 0;
};

forvalues j = 1979(1)2012 {;
gen mom_family_size`j' = 0;

forvalues kid = 1(1)10 {;
replace mom_family_size`j' = mom_family_size`j' + 1 if child_ybirth`kid' <= `j' & child_ybirth`kid' ~= .;
};

};

*check;
tab mom_family_size2012 numbkids_ever, m;


***************************************************************************************;
*mother's cognitive and non-cognitive
***************************************************************************************;

*renaming for consistency with CHS variable names;
rename asvab_4_1981 asvab2;
rename asvab_5_1981 asvab3;
rename asvab_6_1981 asvab4;
rename asvab_7_1981 asvab5;
rename asvab_8_1981 asvab6;
rename asvab_10_1981 asvab8;

rename rosenberg_esteem_000001_1980 se1;
rename rosenberg_esteem_000002_1980 se2;
rename rosenberg_esteem_000003_1980 se3;
rename rosenberg_esteem_000004_1980 se4;
rename rosenberg_esteem_000005_1980 se5;
rename rosenberg_esteem_000006_1980 se6;
rename rosenberg_esteem_000008_1980 se8;
rename rosenberg_esteem_000009_1980 se9;
rename rosenberg_esteem_000010_1980 se10;

order se*;

gen rotter1=-7;
gen rotter2=-7;
gen rotter3=-7;
gen rotter4=-7;

*Generate rotter values from answers in the questionnaire;
replace rotter1=4 if rotter_1a_1979==1 & rotter_1b_1979==1;
replace rotter1=3 if rotter_1a_1979==1 & rotter_1b_1979==2;
replace rotter1=2 if rotter_1a_1979==2 & rotter_1b_1979==2;
replace rotter1=1 if rotter_1a_1979==2 & rotter_1b_1979==1;

replace rotter2=4 if rotter_2a_1979==1 & rotter_2b_1979==1;
replace rotter2=3 if rotter_2a_1979==1 & rotter_2b_1979==2;
replace rotter2=2 if rotter_2a_1979==2 & rotter_2b_1979==2;
replace rotter2=1 if rotter_2a_1979==2 & rotter_2b_1979==1;

replace rotter3=4 if rotter_3a_1979==1 & rotter_3b_1979==1;
replace rotter3=3 if rotter_3a_1979==1 & rotter_3b_1979==2;
replace rotter3=2 if rotter_3a_1979==2 & rotter_3b_1979==2;
replace rotter3=1 if rotter_3a_1979==2 & rotter_3b_1979==1;

replace rotter4=4 if rotter_4a_1979==2 & rotter_4b_1979==1;
replace rotter4=3 if rotter_4a_1979==2 & rotter_4b_1979==2;
replace rotter4=2 if rotter_4a_1979==1 & rotter_4b_1979==2;
replace rotter4=1 if rotter_4a_1979==1 & rotter_4b_1979==1;

order rotter*;

forvalues j=1986(2)2012 {;
forvalues i = 1(1)6 {;
          
		gen se`i'`j' = se`i';
		  
		  };
		  
		  
forvalues i = 8(1)10 {;
          
		gen se`i'`j' = se`i';
		  
		  };		  
		  
		  
};

forvalues i = 1(1)6 {;          
drop se`i';
};
		  
		  
forvalues i = 8(1)10 {;
drop se`i';
};
		  
		  
		  
forvalues j=1986(2)2012 {;
		  
forvalues i =2(1)6 {;		 
		  
		  gen asvab`i'`j' = asvab`i';
		  
		  };
};

forvalues i =2(1)6 {;		 

drop asvab`i';
};

forvalues j=1986(2)2012 {;
gen asvab8`j'=asvab8;
};
drop asvab8;

forvalues j=1986(2)2012 {;
		  
forvalues i =1(1)4 {;

gen rotter`i'`j'=rotter`i'; 

};

};

forvalues i =1(1)4 {;
drop rotter`i';
};	 



***************************************************************************************;
*rename cognitive and non-cognitive child data
***************************************************************************************;

local year_list = "1986 1988 1990 1992 1994 1996 1998 2000 2002 2004 2006 2008 2010 2012";
local var_list = "math recog comp ppvt comply insecur sociab anti anx head hypr dep peer digit";
foreach Y of local year_list {;
foreach X of local var_list {;
rename `X'`Y'_`Y' `X'`Y';
};
};

local year_list = "1986 1988 1990 1992 1994 1996 1998 2000 2008 2010";
local var_list = "actvty predct";
foreach Y of local year_list {;
foreach X of local var_list {;
rename `X'`Y'_`Y' `X'`Y';
};
};

local year_list = "1986 1988 1990 1992 1994 1996 1998 2000 2002 2008 2010 2012";
local var_list = "fear affect negatv diffic friend";
foreach Y of local year_list {;
foreach X of local var_list {;
rename `X'`Y'_`Y' `X'`Y';
};
};

local year_list = "1986 1988 1990 1992 1994 1996 1998 2000 2002 2006 2008 2010 2012";
local var_list = "moto";
foreach Y of local year_list {;
foreach X of local var_list {;
rename `X'`Y'_`Y' `X'`Y';
};
}; 

local year_list = "1986 1988";
local var_list = "body loca";
foreach Y of local year_list {;
foreach X of local var_list {;
rename `X'`Y'_`Y' `X'`Y';
};
};

local year_list = "1986 1988 1990 1992 1994 1996 1998 2000 2002 2004 2006 2008 2010 2012";
local var_list = "weight_atbirth gest_length education wage_children";
foreach Y of local year_list {;
foreach X of local var_list {;
gen `X'`Y' =`X' ;
};
};
drop weight_atbirth;
drop gest_length;
drop education;
drop wage_children;

***************************************************************************************;
*rename investment data
***************************************************************************************;

*************;
*Often out of house;
*************;

*Fix the investment measures;

local i = 1; 
foreach X of varlist ms860168_1986 ms880330_1988 ms900363_1990 ms920363_1992
ms940371_1994 ms960371_1996 ms981b09_1998  {;

gen temp`i' = .;

replace temp`i' = 5 if `X'==4;
replace temp`i' = 7 if `X'==5;

replace `X' = temp`i' if temp`i'~=.;

drop temp`i';

};
               
gen often_house1986=-7;
replace often_house1986 = ms860127_1986 if ms860127_1986>=0 ;   
replace often_house1986 = ms860168_1986 if ms860168_1986>=0;

gen often_house1988=-7;
replace often_house1988 = ms880244_1988 if ms880244_1988>=0;
replace often_house1988 = ms880330_1988 if ms880330_1988>=0;

gen often_house1990=-7;
replace often_house1990 = ms900243_1990 if ms900243_1990>=0;
replace often_house1990 = ms900363_1990 if ms900363_1990>=0;

gen often_house1992=-7;
replace often_house1992 = ms920243_1992 if ms920243_1992>=0;
replace often_house1992 = ms920363_1992 if ms920363_1992>=0;
   
gen often_house1994=-7;   
replace often_house1994 = ms940243_1994 if ms940243_1994>=0;
replace often_house1994 = ms940371_1994 if ms940371_1994>=0;
        
gen often_house1996=-7;   
replace often_house1996 = ms960243_1996 if ms960243_1996>=0;
replace often_house1996 = ms960371_1996 if ms960371_1996>=0;

gen often_house1998=-7;   
replace often_house1998 = ms981a01_1998 if ms981a01_1998>=0;   
replace often_house1998 = ms981b09_1998 if ms981b09_1998>=0;
                
gen often_house2000=-7;
replace often_house2000 = ms1_a09_2000 if ms1_a09_2000>=0;

gen often_house2002=-7;
replace often_house2002 = home_a01_2002 if home_a01_2002>=0;
replace often_house2002 = home_b09_2002 if home_b09_2002>=0;

gen often_house2004=-7;
replace often_house2004 = home_a01_2004 if home_a01_2004>=0;
replace often_house2004 = home_b09_2004 if home_b09_2004>=0;

gen often_house2006=-7;
replace often_house2006 = ms_home_a01_2006 if ms_home_a01_2006>=0; 
replace often_house2006 = ms_home_b09_2006 if ms_home_b09_2006>=0;

gen often_house2008=-7;
replace often_house2008 = ms_home_a01_2008 if ms_home_a01_2008>=0;
replace often_house2008 = ms_home_b09_2008 if ms_home_b09_2008>=0;
          		 
gen often_house2010=-7;		  
replace often_house2010 = ms_home_a01_2010 if ms_home_a01_2010>=0;
replace often_house2010 = ms_home_b09_2010 if ms_home_b09_2010>=0;

gen often_house2012=-7;
replace often_house2012 = ms_home_a01_2012 if ms_home_a01_2012>=0;
replace often_house2012 = ms_home_b09_2012 if ms_home_b09_2012>=0;



**************;
*Recoding Number of books;
**************;

gen number_books1986= -7; 
replace number_books1986 = ms860129_1986 if ms860129_1986>=0;
replace number_books1986 =  ms860144_1986 if  ms860144_1986>=0;
replace number_books1986 =  ms860212_1986 if  ms860212_1986>=0;


replace number_books1986 = 0 if number_books1986==1;
replace number_books1986 = 1.5 if number_books1986==2;
replace number_books1986 = 6 if number_books1986==3;
replace number_books1986 = 10 if number_books1986==4;


gen number_books1988=-7;
replace number_books1988 = ms880246_1988 if ms880246_1988>=0;
replace number_books1988 = ms880261_1988 if ms880261_1988>=0;
replace number_books1988 = ms880337_1988 if ms880337_1988>=0;
replace number_books1988 = 0 if number_books1988==1;
replace number_books1988 = 1.5 if number_books1988==2;
replace number_books1988 = 6 if number_books1988==3;
replace number_books1988 = 10 if number_books1988==4;

replace number_books1988 = ms880436_1988 if ms880436_1988>=0;
replace number_books1988 = 0 if number_books1988==1;
replace number_books1988 = 5 if number_books1988==2;
replace number_books1988 = 14.5 if number_books1988==3;
replace number_books1988 = 20 if number_books1988==4;


gen number_books1990=-7;
replace number_books1990 = ms900245_1990 if ms900245_1990>=0;
replace number_books1990 = ms900325_1990 if ms900325_1990>=0;
replace number_books1990 = ms900427_1990 if ms900427_1990>=0;
replace number_books1990 = 0 if number_books1990==1;
replace number_books1990 = 1.5 if number_books1990==2;
replace number_books1990 = 6 if number_books1990==3;
replace number_books1990 = 10 if number_books1990==4;

replace number_books1990 = ms900569_1990 if ms900569_1990>=0;
replace number_books1990 = 0 if number_books1990==1;
replace number_books1990 = 5 if number_books1990==2;
replace number_books1990 = 14.5 if number_books1990==3;
replace number_books1990 = 20 if number_books1990==4;


gen number_books1992=-7;
replace number_books1992 = ms920245_1992 if ms920245_1992>=0;
replace number_books1992 = ms920325_1992 if ms920325_1992>=0;
replace number_books1992 = ms920427_1992 if ms920427_1992>=0;
replace number_books1992 = 0 if number_books1992==1;
replace number_books1992 = 1.5 if number_books1992==2;
replace number_books1992 = 6 if number_books1992==3;
replace number_books1992 = 10 if number_books1992==4;

replace number_books1992 = ms920571_1992 if ms920571_1992>=0;
replace number_books1992 = 0 if number_books1992==1;
replace number_books1992 = 5 if number_books1992==2;
replace number_books1992 = 14.5 if number_books1992==3;
replace number_books1992 = 20 if number_books1992==4;


gen number_books1994=-7;    
replace number_books1994 = ms940245_1994 if ms940245_1994>=0;
replace number_books1994 = ms940333_1994 if ms940333_1994>=0;
replace number_books1994 = ms940435_1994 if ms940435_1994>=0;
replace number_books1994 = 0 if number_books1994==1;
replace number_books1994 = 1.5 if number_books1994==2;
replace number_books1994 = 6 if number_books1994==3;
replace number_books1994 = 10 if number_books1994==4;

replace number_books1994 = ms940627_1994 if ms940627_1994>=0;	
replace number_books1994 = 0 if number_books1994==1;
replace number_books1994 = 5 if number_books1994==2;
replace number_books1994 = 14.5 if number_books1994==3;
replace number_books1994 = 20 if number_books1994==4;


gen number_books1996=-7;	
replace number_books1996 = ms960245_1996 if ms960245_1996>=0;
replace number_books1996 = ms960331_1996 if ms960331_1996>=0;
replace number_books1996 = ms960433_1996 if ms960433_1996>=0;
replace number_books1996 = 0 if number_books1996==1;
replace number_books1996 = 1.5 if number_books1996==2;
replace number_books1996 = 6 if number_books1996==3;
replace number_books1996 = 10 if number_books1996==4;

replace number_books1996 = ms960627_1996 if ms960627_1996>=0;		
replace number_books1996 = 0 if number_books1996==1;
replace number_books1996 = 5 if number_books1996==2;
replace number_books1996 = 14.5 if number_books1996==3;
replace number_books1996 = 20 if number_books1996==4;


gen number_books1998=-7;	
replace number_books1998 = ms981a02_1998 if ms981a02_1998>=0;
replace number_books1998 = ms981b02_1998 if ms981b02_1998>=0;
replace number_books1998 = ms981c01_1998 if ms981c01_1998>=0;
replace number_books1998 = 0 if number_books1998==1;
replace number_books1998 = 1.5 if number_books1998==2;
replace number_books1998 = 6 if number_books1998==3;
replace number_books1998 = 10 if number_books1998==4;

replace number_books1998 = ms981d01_1998 if ms981d01_1998>=0;	
replace number_books1998 = 0 if number_books1998==1;
replace number_books1998 = 5 if number_books1998==2;
replace number_books1998 = 14.5 if number_books1998==3;
replace number_books1998 = 20 if number_books1998==4;


gen number_books2000=-7;    
replace number_books2000 = ms1_a02_2000 if ms1_a02_2000>=0;
replace number_books2000 = ms1_b01_2000 if ms1_b01_2000>=0;
replace number_books2000 = 0 if number_books2000==1;
replace number_books2000 = 1.5 if number_books2000==2;
replace number_books2000 = 6 if number_books2000==3;
replace number_books2000 = 10 if number_books2000==4;

replace number_books2000 = ms1_c01_2000 if ms1_c01_2000>=0;
replace number_books2000 = 0 if number_books2000==1;
replace number_books2000 = 5 if number_books2000==2;
replace number_books2000 = 14.5 if number_books2000==3;
replace number_books2000 = 20 if number_books2000==4;

		
gen number_books2002=-7;	
replace number_books2002 = home_a02_2002 if home_a02_2002>=0;
replace number_books2002 = home_b02_2002 if home_b02_2002>=0;
replace number_books2002 = home_c01_2002 if home_c01_2002>=0;
replace number_books2002 = 0 if number_books2002==1;
replace number_books2002 = 1.5 if number_books2002==2;
replace number_books2002 = 6 if number_books2002==3;
replace number_books2002 = 10 if number_books2002==4;
		
replace number_books2002 = home_d01_2002 if home_d01_2002>=0;
replace number_books2002 = 0 if number_books2002==1;
replace number_books2002 = 5 if number_books2002==2;
replace number_books2002 = 14.5 if number_books2002==3;
replace number_books2002 = 20 if number_books2002==4;

	
gen number_books2004=-7;	
replace number_books2004 = home_a02_2004 if home_a02_2004>=0;
replace number_books2004 = home_b02_2004 if home_b02_2004>=0;
replace number_books2004 = home_c01_2004 if home_c01_2004>=0;
replace number_books2004 = 0 if number_books2004==1;
replace number_books2004 = 1.5 if number_books2004==2;
replace number_books2004 = 6 if number_books2004==3;
replace number_books2004 = 10 if number_books2004==4;
		
replace number_books2004 = home_d01_2004 if home_d01_2004>=0;
replace number_books2004 = 0 if number_books2004==1;
replace number_books2004 = 5 if number_books2004==2;
replace number_books2004 = 14.5 if number_books2004==3;
replace number_books2004 = 20 if number_books2004==4;


gen number_books2006=-7;
replace number_books2006 = ms_home_a02_2006 if ms_home_a02_2006>=0;
replace number_books2006 = ms_home_b02_2006 if ms_home_b02_2006>=0;
replace number_books2006 = ms_home_c01_2006 if ms_home_c01_2006>=0;		
replace number_books2006 = 0 if number_books2006==1;
replace number_books2006 = 1.5 if number_books2006==2;
replace number_books2006 = 6 if number_books2006==3;
replace number_books2006 = 10 if number_books2006==4;

replace number_books2006 = ms_home_d01_2006 if ms_home_d01_2006>=0;
replace number_books2006 = 0 if number_books2006==1;
replace number_books2006 = 5 if number_books2006==2;
replace number_books2006 = 14.5 if number_books2006==3;
replace number_books2006 = 20 if number_books2006==4;

   
gen number_books2008=-7;
replace number_books2008 = ms_home_a02_2008 if ms_home_a02_2008>=0;
replace number_books2008 = ms_home_b02_2008 if ms_home_b02_2008>=0;
replace number_books2008 = ms_home_c01_2008 if ms_home_c01_2008>=0;	
replace number_books2008 = 0 if number_books2008==1;
replace number_books2008 = 1.5 if number_books2008==2;
replace number_books2008 = 6 if number_books2008==3;
replace number_books2008 = 10 if number_books2008==4;
	
replace number_books2008 = ms_home_d01_2008 if ms_home_d01_2008>=0;
replace number_books2008 = 0 if number_books2008==1;
replace number_books2008 = 5 if number_books2008==2;
replace number_books2008 = 14.5 if number_books2008==3;
replace number_books2008 = 20 if number_books2008==4;   



gen number_books2010=-7;
replace number_books2010 =  ms_home_a02_2010 if ms_home_a02_2010>=0;
replace number_books2010 =  ms_home_b02_2010 if ms_home_b02_2010>=0;
replace number_books2010 =  ms_home_c01_2010 if ms_home_c01_2010>=0;
replace number_books2010 = 0 if number_books2010==1;
replace number_books2010 = 1.5 if number_books2010==2;
replace number_books2010 = 6 if number_books2010==3;
replace number_books2010 = 10 if number_books2010==4;
		
replace number_books2010 =  ms_home_d01_2010 if ms_home_d01_2010>=0;
replace number_books2010 = 0 if number_books2010==1;
replace number_books2010 = 5 if number_books2010==2;
replace number_books2010 = 14.5 if number_books2010==3;
replace number_books2010 = 20 if number_books2010==4;

   
gen number_books2012=-7;
replace number_books2012 = ms_home_a02_2012 if ms_home_a02_2012>=0;
replace number_books2012 = ms_home_b02_2012 if ms_home_b02_2012>=0;
replace number_books2012 = ms_home_c01_2012 if ms_home_c01_2012>=0;		
replace number_books2012 = 0 if number_books2012==1;
replace number_books2012 = 1.5 if number_books2012==2;
replace number_books2012 = 6 if number_books2012==3;
replace number_books2012 = 10 if number_books2012==4;

replace number_books2012 = ms_home_d01_2012 if ms_home_d01_2012>=0;
replace number_books2012 = 0 if number_books2012==1;
replace number_books2012 = 5 if number_books2012==2;
replace number_books2012 = 14.5 if number_books2012==3;
replace number_books2012 = 20 if number_books2012==4;


	


**************;
*Recoding Soft Toys;
**************;
gen number_soft_toys1986=-7;
gen number_soft_toys1988=-7;
gen number_soft_toys1990=-7;
gen number_soft_toys1992=-7;
gen number_soft_toys1994=-7;
gen number_soft_toys1996=-7;
gen number_soft_toys1998=-7;

gen number_soft_toys2002=-7;
gen number_soft_toys2004=-7;
gen number_soft_toys2006=-7;
gen number_soft_toys2008=-7;
gen number_soft_toys2010=-7;
gen number_soft_toys2012=-7;


replace number_soft_toys1986 = ms860132_1986 if ms860132_1986>=0 & ms860132_1986<=50; 
replace number_soft_toys1988 = ms880249_1988 if ms880249_1988>=0 & ms880249_1988<=50;
replace number_soft_toys1990 = ms900251_1990 if ms900251_1990>=0 & ms900251_1990<=50;
replace number_soft_toys1992 = ms920251_1992 if ms920251_1992>=0 & ms920251_1992<=50;
replace number_soft_toys1994 = ms940251_1994 if ms940251_1994>=0 & ms940251_1994<=50;
replace number_soft_toys1996 = ms960251_1996 if ms960251_1996>=0 & ms960251_1996<=50;
replace number_soft_toys1998 = ms981a05_1998 if ms981a05_1998>=0 & ms981a05_1998<=50;

replace number_soft_toys2002 = home_a05_2002 if home_a05_2002>=0 & home_a05_2002<=50;
replace number_soft_toys2004 = home_a05_2004 if home_a05_2004>=0 & home_a05_2004<=50;
replace number_soft_toys2006 = ms_home_a05_2006 if ms_home_a05_2006>=0 & ms_home_a05_2006<=50;
replace number_soft_toys2008 = ms_home_a05_2008 if ms_home_a05_2008>=0 & ms_home_a05_2008<=50;
replace number_soft_toys2010 = ms_home_a05_2010 if ms_home_a05_2010>=0 & ms_home_a05_2010<=50;
replace number_soft_toys2012 = ms_home_a05_2012 if ms_home_a05_2012>=0 & ms_home_a05_2012<=50;


**************;
*Recoding Push Toys;
**************;

gen number_push_toys1986=-7;
gen number_push_toys1988=-7;
gen number_push_toys1990=-7;
gen number_push_toys1992=-7;
gen number_push_toys1994=-7;
gen number_push_toys1996=-7;
gen number_push_toys1998=-7;

gen number_push_toys2002=-7;
gen number_push_toys2004=-7;
gen number_push_toys2006=-7;
gen number_push_toys2008=-7;
gen number_push_toys2010=-7;
gen number_push_toys2012=-7;

replace number_push_toys1986 = ms860134_1986 if ms860134_1986>=0 & ms860134_1986<=30;
replace number_push_toys1988 = ms880251_1988 if ms880251_1988>=0 & ms880251_1988<=30;
replace number_push_toys1990 = ms900253_1990 if ms900253_1990>=0 & ms900253_1990<=30;
replace number_push_toys1992 = ms920253_1992 if ms920253_1992>=0 & ms920253_1992<=30;
replace number_push_toys1994 = ms940253_1994 if ms940253_1994>=0 & ms940253_1994<=30;
replace number_push_toys1996 = ms960253_1996 if ms960253_1996>=0 & ms960253_1996<=30;
replace number_push_toys1998 = ms981a06_1998 if ms981a05_1998>=0 & ms981a05_1998<=30;

replace number_push_toys2002 = home_a06_2002 if home_a06_2002>=0 & home_a06_2002<=30;
replace number_push_toys2004 = home_a06_2004 if home_a06_2004>=0 & home_a06_2004<=30;
replace number_push_toys2006 = ms_home_a06_2006 if ms_home_a06_2006>=0 & ms_home_a06_2006<=30;
replace number_push_toys2008 = ms_home_a06_2008 if ms_home_a06_2008>=0 & ms_home_a06_2008<=30;
replace number_push_toys2010 = ms_home_a06_2010 if ms_home_a06_2010>=0 & ms_home_a06_2010<=30;
replace number_push_toys2012 = ms_home_a06_2012 if ms_home_a06_2012>=0 & ms_home_a06_2012<=30;



**************;
*Recoding number magazines;
**************;

gen number_magazines1986=-7;
gen number_magazines1988=-7;
gen number_magazines1990=-7;
gen number_magazines1992=-7;
gen number_magazines1994=-7;
gen number_magazines1996=-7;
gen number_magazines1998=-7;
gen number_magazines2000=-7;
gen number_magazines2002=-7;
gen number_magazines2004=-7;
gen number_magazines2006=-7;
gen number_magazines2008=-7;
gen number_magazines2010=-7;
gen number_magazines2012=-7;


replace number_magazines1986 = ms860145_1986-1 if ms860145_1986>=0;
replace number_magazines1988 = ms880262_1988-1 if ms880262_1988>=0;
replace number_magazines1990 = ms900327_1990-1 if ms900327_1990>=0;
replace number_magazines1992 = ms920327_1992-1 if ms920327_1992>=0;
replace number_magazines1994 = ms940335_1994-1 if ms940335_1994>=0;
replace number_magazines1996 = ms960333_1996-1 if ms960333_1996>=0;
replace number_magazines1998 = ms981b03_1998-1 if ms981b03_1998>=0;
replace number_magazines2000 = ms1_a03_2000-1 if ms1_a03_2000>=0;
replace number_magazines2002 = home_b03_2002-1 if home_b03_2002>=0;
replace number_magazines2004 = home_b03_2004-1 if home_b03_2004>=0;
replace number_magazines2006 = ms_home_b03_2006-1 if ms_home_b03_2006>=0;
replace number_magazines2008 = ms_home_b03_2008-1 if ms_home_b03_2008>=0;
replace number_magazines2010 = ms_home_b03_2010-1 if ms_home_b03_2010>=0;
replace number_magazines2012 = ms_home_b03_2012-1 if ms_home_b03_2012>=0;



*************;
*has tape/cd;
**************;
gen has_tape_cd1986=-7;
gen has_tape_cd1988=-7;
gen has_tape_cd1990=-7;
gen has_tape_cd1992=-7;
gen has_tape_cd1994=-7;
gen has_tape_cd1996=-7;
gen has_tape_cd1998=-7;
gen has_tape_cd2000=-7;
gen has_tape_cd2002=-7;
gen has_tape_cd2004=-7;
gen has_tape_cd2006=-7;
gen has_tape_cd2008=-7;
gen has_tape_cd2010=-7;
gen has_tape_cd2012=-7;


replace has_tape_cd1986 = ms860146_1986 if ms860146_1986>=0;
replace has_tape_cd1988 = ms880263_1988 if ms880263_1988>=0;
replace has_tape_cd1990 = ms900329_1990 if ms900329_1990>=0;
replace has_tape_cd1992 = ms920329_1992 if ms920329_1992>=0;
replace has_tape_cd1994 = ms940337_1994 if ms940337_1994>=0;
replace has_tape_cd1996 = ms960335_1996 if ms960335_1996>=0;
replace has_tape_cd1998 = ms981b04_1998 if ms981b04_1998>=0;
replace has_tape_cd2000 = ms1_a04_2000 if ms1_a04_2000>=0;
replace has_tape_cd2002 = home_b04_2002 if home_b04_2002>=0;
replace has_tape_cd2004 = home_b04_2004 if home_b04_2004>=0;
replace has_tape_cd2006 = ms_home_b04_2006 if ms_home_b04_2006>=0;
replace has_tape_cd2008 = ms_home_b04_2008 if ms_home_b04_2008>=0;
replace has_tape_cd2010 = ms_home_b04_2010 if ms_home_b04_2010>=0;
replace has_tape_cd2012 = ms_home_b04_2012 if ms_home_b04_2012>=0;
 

 
*************;
*has musical instrument;
**************;
gen has_musical_instrument1986 = -7;
gen has_musical_instrument1988 = -7;
gen has_musical_instrument1990 = -7;
gen has_musical_instrument1992 = -7;

replace has_musical_instrument1986 = ms860219_1986 if ms860219_1986>=0;

replace has_musical_instrument1988 = ms880344_1988 if ms880344_1988>=0;

replace has_musical_instrument1990 = ms900441_1990 if ms900441_1990>=0;

replace has_musical_instrument1992 = ms920441_1992 if ms920441_1992>=0; 


gen has_musical_instrument1994=-7;
replace has_musical_instrument1994 = ms940449_1994 if ms940449_1994>=0;
replace has_musical_instrument1994 = ms940641_1994 if ms940641_1994>=0;

gen has_musical_instrument1996=-7;
replace has_musical_instrument1996 = ms960447_1996 if ms960447_1996>=0;
replace has_musical_instrument1996 = ms960641_1996 if ms960641_1996>=0;

gen has_musical_instrument1998=-7;
replace has_musical_instrument1998 = ms981c04_1998 if ms981c04_1998>=0;
replace has_musical_instrument1998 = ms981d03_1998 if ms981d03_1998>=0;

gen has_musical_instrument2000=-7;
replace has_musical_instrument2000 = ms1_b04_2000 if ms1_b04_2000>=0;
replace has_musical_instrument2000 = ms1_c03_2000 if ms1_c03_2000>=0;

gen has_musical_instrument2002=-7;
replace has_musical_instrument2002 = home_c04_2002 if home_c04_2002>=0;
replace has_musical_instrument2002 = home_d03_2002 if home_d03_2002>=0;

gen has_musical_instrument2004=-7;
replace has_musical_instrument2004 = home_c04_2004 if home_c04_2004>=0;
replace has_musical_instrument2004 = home_d03_2004 if home_d03_2004>=0;

gen has_musical_instrument2006=-7;
replace has_musical_instrument2006 = ms_home_c04_2006 if ms_home_c04_2006>=0;
replace has_musical_instrument2006 = ms_home_d03_2006 if ms_home_d03_2006>=0;

gen has_musical_instrument2008=-7;
replace has_musical_instrument2008 = ms_home_c04_2008 if ms_home_c04_2008>=0;
replace has_musical_instrument2008 = ms_home_d03_2008 if ms_home_d03_2008>=0;

gen has_musical_instrument2010=-7;
replace has_musical_instrument2010 = ms_home_c04_2010 if ms_home_c04_2010>=0;
replace has_musical_instrument2010 = ms_home_d03_2010 if ms_home_d03_2010>=0;

gen has_musical_instrument2012=-7;
replace has_musical_instrument2012 = ms_home_c04_2012 if ms_home_c04_2012>=0;
replace has_musical_instrument2012 = ms_home_d03_2012 if ms_home_d03_2012>=0;
  

  

*************;
*has newspaper;
**************;         			  
gen has_newspaper1986=-7;			  
replace has_newspaper1986 = ms860220_1986 if ms860220_1986>=0;

gen has_newspaper1988=-7; 			  
replace has_newspaper1988 = ms880345_1988 if ms880345_1988>=0;			  			  
replace has_newspaper1988 = ms880444_1988 if ms880444_1988>=0;

gen has_newspaper1990=-7;
replace has_newspaper1990 = ms900443_1990 if ms900443_1990>=0;			  			  
replace has_newspaper1990 = ms900625_1990 if ms900625_1990>=0;

gen has_newspaper1992=-7;			  
replace has_newspaper1992 = ms920443_1992 if ms920443_1992>=0;			  			  
replace has_newspaper1992 = ms920625_1992 if ms920625_1992>=0 & ms920625_1992<=1;


gen has_newspaper1994=-7;
replace has_newspaper1994 = ms940451_1994 if ms940451_1994>=0;			  			  
replace has_newspaper1994 = ms940643_1994 if ms940643_1994>=0;


gen has_newspaper1996=-7;
replace has_newspaper1996 = ms960449_1996 if ms960449_1996>=0;			  			  
replace has_newspaper1996 = ms960643_1996 if ms960643_1996>=0;

gen has_newspaper1998=-7;
replace has_newspaper1998 = ms981c05_1998 if ms981c05_1998>=0;
replace has_newspaper1998 = ms981d04_1998 if ms981d04_1998>=0;	

gen has_newspaper2000=-7;
replace has_newspaper2000 = ms1_b05_2000 if ms1_b05_2000>=0;
replace has_newspaper2000 = ms1_c04_2000 if ms1_c04_2000>=0;	

gen has_newspaper2002=-7;
replace has_newspaper2002 = home_c05_2002 if home_c05_2002>=0;
replace has_newspaper2002 = home_d04_2002 if home_d04_2002>=0;	

gen has_newspaper2004=-7;
replace has_newspaper2004 = home_c05_2004 if home_c05_2004>=0;			  			  
replace has_newspaper2004 = home_d04_2004 if home_d04_2004>=0;	

gen has_newspaper2006=-7;
replace has_newspaper2006 = ms_home_c05_2006 if ms_home_c05_2006>=0 & ms_home_c05_2006<=1;			  			  
replace has_newspaper2006 = ms_home_d04_2006 if ms_home_d04_2006>=0;	

gen has_newspaper2008=-7;
replace has_newspaper2008 = ms_home_c05_2008 if ms_home_c05_2008>=0 & ms_home_c05_2008<=1;			  			  
replace has_newspaper2008 = ms_home_d04_2008 if ms_home_d04_2008>=0;	

gen has_newspaper2010=-7;
replace has_newspaper2010 = ms_home_c05_2010 if ms_home_c05_2010>=0 & ms_home_c05_2010<=1;			  			  
replace has_newspaper2010 = ms_home_d04_2010 if ms_home_d04_2010>=0;	

gen has_newspaper2012=-7;
replace has_newspaper2012 = ms_home_c05_2012 if ms_home_c05_2012>=0 & ms_home_c05_2012<=1;			  			  
replace has_newspaper2012 = ms_home_d04_2012 if ms_home_d04_2012>=0;	


 
*Time Investments  
   
**************;
*Mom reads to child;
**************;  


gen often_mom_reads1986=-7;
replace often_mom_reads1986 =  ms860130_1986 if ms860130_1986>=0;   
replace often_mom_reads1986 = ms860143_1986 if ms860143_1986>=0;
replace often_mom_reads1986 = ms860213_1986 if ms860213_1986>=0;

gen often_mom_reads1988=-7;
replace often_mom_reads1988 = ms880247_1988 if ms880247_1988>=0;
replace often_mom_reads1988 = ms880260_1988 if ms880260_1988>=0;
replace often_mom_reads1988 = ms880338_1988 if ms880338_1988>=0;

gen often_mom_reads1990=-7;
replace often_mom_reads1990 = ms900247_1990 if ms900247_1990>=0;
replace often_mom_reads1990 = ms900323_1990 if ms900323_1990>=0;
replace often_mom_reads1990 = ms900429_1990 if ms900429_1990>=0;

gen often_mom_reads1992=-7;
replace often_mom_reads1992 = ms920247_1992 if ms920247_1992>=0;
replace often_mom_reads1992 = ms920323_1992 if ms920323_1992>=0;
replace often_mom_reads1992 = ms920429_1992 if ms920429_1992>=0;
   
gen often_mom_reads1994=-7;   
replace often_mom_reads1994 = ms940247_1994 if ms940247_1994>=0;
replace often_mom_reads1994 = ms940331_1994 if ms940331_1994>=0;
replace often_mom_reads1994 = ms940437_1994 if ms940437_1994>=0;
   
   
gen often_mom_reads1996=-7;   
replace often_mom_reads1996 = ms960247_1996 if ms960247_1996>=0;
replace often_mom_reads1996 = ms960329_1996 if ms960329_1996>=0;
replace often_mom_reads1996 = ms960435_1996 if ms960435_1996>=0;

gen often_mom_reads1998=-7;   
replace often_mom_reads1998 = ms981a03_1998 if ms981a03_1998>=0;   
replace often_mom_reads1998 = ms981b01_1998 if ms981b01_1998>=0;
replace often_mom_reads1998 = ms981c02_1998 if ms981c02_1998>=0;   

gen often_mom_reads2000=-7;
*In the year 2000 this variable is available only for children of age (4-5) and (6-9);
replace often_mom_reads2000 = ms1_a01_2000 if ms1_a01_2000>=0;
replace often_mom_reads2000 = ms1_b02_2000 if ms1_b02_2000>=0 & ms1_b02_2000<=6;


gen often_mom_reads2002=-7;
replace often_mom_reads2002 = home_a03_2002 if home_a03_2002>=0;
replace often_mom_reads2002 = home_b01_2002 if home_b01_2002>=0;
replace often_mom_reads2002 = home_c02_2002 if home_c02_2002>=0;   

gen often_mom_reads2004=-7;
replace often_mom_reads2004 = home_a03_2004 if home_a03_2004>=0;
replace often_mom_reads2004 = home_b01_2004 if home_b01_2004>=0;
replace often_mom_reads2004 = home_c02_2004 if home_c02_2004>=0;   

gen often_mom_reads2006=-7;
replace often_mom_reads2006 = ms_home_a03_2006 if ms_home_a03_2006>=0; 
replace often_mom_reads2006 = ms_home_b01_2006 if ms_home_b01_2006>=0;
replace often_mom_reads2006 = ms_home_c02_2006 if ms_home_c02_2006>=0;


gen often_mom_reads2008=-7;
replace often_mom_reads2008 = ms_home_a03_2008 if ms_home_a03_2008>=0;
replace often_mom_reads2008 = ms_home_b01_2008 if ms_home_b01_2008>=0;
replace often_mom_reads2008 = ms_home_c02_2008 if ms_home_c02_2008>=0;
          
		  
gen often_mom_reads2010=-7;		  
replace often_mom_reads2010 = ms_home_a03_2010 if ms_home_a03_2010>=0;
replace often_mom_reads2010 = ms_home_b01_2010 if ms_home_b01_2010>=0;
replace often_mom_reads2010 = ms_home_c02_2010 if ms_home_c02_2010>=0;

gen often_mom_reads2012=-7;
replace often_mom_reads2012 = ms_home_a03_2012 if ms_home_a03_2012>=0;
replace often_mom_reads2012 = ms_home_b01_2012 if ms_home_b01_2012>=0;
replace often_mom_reads2012 = ms_home_c02_2012 if ms_home_c02_2012>=0;		  
		  


**************;
*Child eats with Mom;
**************;        
gen often_eats_mom1986 = -7;
gen often_eats_mom1988 = -7;
gen often_eats_mom1990 = -7;
gen often_eats_mom1992 = -7;
gen often_eats_mom1994 = -7;
gen often_eats_mom1996 = -7;
gen often_eats_mom1998 = -7;
gen often_eats_mom2000 = -7;
gen often_eats_mom2002 = -7;
gen often_eats_mom2004 = -7;
gen often_eats_mom2006 = -7;
gen often_eats_mom2008 = -7;
gen often_eats_mom2010 = -7;
gen often_eats_mom2012 = -7;




replace often_eats_mom1986 = ms860138_1986 if ms860138_1986>=0;   
replace often_eats_mom1986 = ms860171_1986 if ms860171_1986>=0;
replace often_eats_mom1986 = ms860230_1986 if ms860230_1986>=0;

replace often_eats_mom1988 = ms880255_1988 if ms880255_1988>=0 & ms880255_1988<=6;   
replace often_eats_mom1988 = ms880333_1988 if ms880333_1988>=0 & ms880333_1988<=6;
replace often_eats_mom1988 = ms880355_1988 if ms880355_1988>=0 & ms880355_1988<=6;
replace often_eats_mom1988 = ms880454_1988 if ms880454_1988>=0 & ms880454_1988<=6;

 
replace often_eats_mom1990 = ms900317_1990 if ms900317_1990>=0 & ms900317_1990<=6;   
replace often_eats_mom1990 = ms900423_1990 if ms900423_1990>=0 & ms900423_1990<=6;
replace often_eats_mom1990 = ms900513_1990 if ms900513_1990>=0 & ms900513_1990<=6;
replace often_eats_mom1990 = ms900653_1990 if ms900653_1990>=0 & ms900653_1990<=6;

*1992 and 1994 have different score scale.

*replace often_eats_mom1992 = ms920317_1992 if ms920317_1992>=0 & ms920317_1992<=6;
*replace often_eats_mom1992 = ms920423_1992 if ms920423_1992>=0 & ms920423_1992<=6;
*replace often_eats_mom1992 = ms920513_1992 if ms920513_1992>=0 & ms920513_1992<=6;
*replace often_eats_mom1992 = ms920653_1992 if ms920653_1992>=0 & ms920653_1992<=6;


*replace often_eats_mom1994 = ms940317_1994 if ms940317_1994>=0 & ms940317_1994<=6;   
*replace often_eats_mom1994 = ms940423_1994 if ms940423_1994>=0 & ms940423_1994<=6;
*replace often_eats_mom1994 = ms940513_1994 if ms940513_1994>=0 & ms940513_1994<=6;
*replace often_eats_mom1994 = ms940717_1994 if ms940717_1994>=0 & ms940717_1994<=6;

   
   
replace often_eats_mom1996 = ms960263_1996 if ms960263_1996>=0 & ms960263_1996<=6;   
replace often_eats_mom1996 = ms960415_1996 if ms960415_1996>=0 & ms960415_1996<=6;
replace often_eats_mom1996 = ms960467_1996 if ms960467_1996>=0 & ms960467_1996<=6;
replace often_eats_mom1996 = ms960661_1996 if ms960661_1996>=0 & ms960661_1996<=6;


replace often_eats_mom1998 = ms981a15_1998 if ms981a15_1998>=0 & ms981a15_1998<=6;   
replace often_eats_mom1998 = ms981b17_1998 if ms981b17_1998>=0 & ms981b17_1998<=6 ;
replace often_eats_mom1998 = ms981c19_1998 if ms981c19_1998>=0 & ms981c19_1998<=6 ;   
replace often_eats_mom1998 = ms981d18_1998 if ms981d18_1998>=0 & ms981d18_1998<=6 ;   


*In 2000 there are 3 instead of 4 variables for often eats with mom;
replace often_eats_mom2000 = ms1_a17_2000 if ms1_a17_2000>=0 & ms1_a17_2000<=6 ;   
replace often_eats_mom2000 = ms1_b19_2000 if ms1_b19_2000>=0 & ms1_b19_2000<=6 ;
replace often_eats_mom2000 = ms1_c18_2000 if ms1_c18_2000>=0 & ms1_c18_2000<=6 ;

replace often_eats_mom2002 = home_a15_2002 if home_a15_2002>=0 & home_a15_2002<=6;   
replace often_eats_mom2002 = home_b17_2002 if home_b17_2002>=0 & home_b17_2002<=6;
replace often_eats_mom2002 = home_c19_2002 if home_c19_2002>=0 & home_c19_2002<=6; 
replace often_eats_mom2002 = home_d18_2002 if home_d18_2002>=0 & home_d18_2002<=6;

replace often_eats_mom2004 = home_a15_2004 if home_a15_2004>=0 & home_a15_2004<=6;   
replace often_eats_mom2004 = home_b17_2004 if home_b17_2004>=0 & home_b17_2004<=6;
replace often_eats_mom2004 = home_c19_2004 if home_c19_2004>=0 & home_c19_2004<=6;   
replace often_eats_mom2004 = home_d18_2004 if home_d18_2004>=0 & home_d18_2004<=6;   

replace often_eats_mom2006 = ms_home_a15_2006 if ms_home_a15_2006>=0 & ms_home_a15_2006<=6;   
replace often_eats_mom2006 = ms_home_b17_2006 if ms_home_b17_2006>=0 & ms_home_b17_2006<=6;
replace often_eats_mom2006 = ms_home_c19_2006 if ms_home_c19_2006>=0 & ms_home_c19_2006<=6;
replace often_eats_mom2006 = ms_home_d18_2006 if ms_home_d18_2006>=0 & ms_home_d18_2006<=6;

replace often_eats_mom2008 = ms_home_a15_2008 if ms_home_a15_2008>=0 & ms_home_a15_2008<=6;   
replace often_eats_mom2008 = ms_home_b17_2008 if ms_home_b17_2008>=0 & ms_home_b17_2008<=6;
replace often_eats_mom2008 = ms_home_c19_2008 if ms_home_c19_2008>=0 & ms_home_c19_2008<=6;
replace often_eats_mom2008 = ms_home_d18_2008 if ms_home_d18_2008>=0 & ms_home_d18_2008<=6;
          
replace often_eats_mom2010 = ms_home_a15_2010 if ms_home_a15_2010>=0 & ms_home_a15_2010<=6;   
replace often_eats_mom2010 = ms_home_b17_2010 if ms_home_b17_2010>=0 & ms_home_b17_2010<=6;
replace often_eats_mom2010 = ms_home_c19_2010 if ms_home_c19_2010>=0 & ms_home_c19_2010<=6;
replace often_eats_mom2010 = ms_home_d18_2010 if ms_home_d18_2010>=0 & ms_home_d18_2010<=6;

replace often_eats_mom2012 = ms_home_a15_2012 if ms_home_a15_2012>=0 & ms_home_a15_2012<=6;   
replace often_eats_mom2012 = ms_home_b17_2012 if ms_home_b17_2012>=0 & ms_home_b17_2012<=6;
replace often_eats_mom2012 = ms_home_c19_2012 if ms_home_c19_2012>=0 & ms_home_c19_2012<=6;
replace often_eats_mom2012 = ms_home_d18_2012 if ms_home_d18_2012>=0 & ms_home_d18_2012<=6;   


  
  
**************;
*Mom talk with child from work;
**************;       

gen often_mom_talks1986=-7;
gen often_mom_talks1988=-7;
gen often_mom_talks1990=-7;
gen often_mom_talks1992=-7;
gen often_mom_talks1994=-7;
gen often_mom_talks1996=-7;
gen often_mom_talks1998=-7;
*No info about it in 2000;
*gen often_mom_talks2000=-7;
gen often_mom_talks2002=-7;
gen often_mom_talks2004=-7;
gen often_mom_talks2006=-7;
gen often_mom_talks2008=-7;
gen often_mom_talks2010=-7;
gen often_mom_talks2012=-7;


replace often_mom_talks1986 = ms860139_1986 if ms860139_1986>=0;
replace often_mom_talks1988 = ms880256_1988 if ms880256_1988>=0;
replace often_mom_talks1990 = ms900319_1990 if ms900319_1990>=0;
replace often_mom_talks1992 = ms920319_1992 if ms920319_1992>=0;
replace often_mom_talks1994 = ms940319_1994 if ms940319_1994>=0;
replace often_mom_talks1996 = ms960325_1996 if ms960325_1996>=0;
replace often_mom_talks1998 = ms981a16_1998 if ms981a16_1998>=0;
*No info about it in 2000;
*replace often_mom_talks2000 = ms981a05_2000 if ms981a05_2000>=0;
replace often_mom_talks2002 = home_a16_2002 if home_a16_2002>=0;
replace often_mom_talks2004 = home_a16_2004 if home_a16_2004>=0;
replace often_mom_talks2006 = ms_home_a16_2006 if ms_home_a16_2006>=0;
replace often_mom_talks2008 = ms_home_a16_2008 if ms_home_a16_2008>=0;
replace often_mom_talks2010 = ms_home_a16_2010 if ms_home_a16_2010>=0;
replace often_mom_talks2012 = ms_home_a16_2012 if ms_home_a16_2012>=0;

**************;
*Often to the Museum;
**************; 

gen often_museum1986=-7;
gen often_museum1988=-7;
gen often_museum1990=-7;
gen often_museum1992=-7;
gen often_museum1994=-7;
gen often_museum1996=-7;
gen often_museum1998=-7;
gen often_museum2000=-7;
gen often_museum2002=-7;
gen often_museum2004=-7;
gen often_museum2006=-7;
gen often_museum2008=-7;
gen often_museum2010=-7;
gen often_museum2012=-7;

 
 
replace often_museum1986 = ms860169_1986 if ms860169_1986>=0;   
replace often_museum1986 = ms860224_1986 if ms860224_1986>=0;

replace often_museum1988 = ms880331_1988 if ms880331_1988>=0;   
replace often_museum1988 = ms880349_1988 if ms880349_1988>=0;
replace often_museum1988 = ms880448_1988 if ms880448_1988>=0;
  
replace often_museum1990 = ms900365_1990 if ms900365_1990>=0;   
replace often_museum1990 = ms900451_1990 if ms900451_1990>=0;
replace often_museum1990 = ms900633_1990 if ms900633_1990>=0;

replace often_museum1992 = ms920365_1992 if ms920365_1992>=0;
replace often_museum1992 = ms920451_1992 if ms920451_1992>=0;
replace often_museum1992 = ms920633_1992 if ms920633_1992>=0;
 
replace often_museum1994 = ms940373_1994 if ms940373_1994>=0;   
replace often_museum1994 = ms940459_1994 if ms940459_1994>=0;
replace often_museum1994 = ms940651_1994 if ms940651_1994>=0;

replace often_museum1996 = ms960373_1996 if ms960373_1996>=0;   
replace often_museum1996 = ms960457_1996 if ms960457_1996>=0;
replace often_museum1996 = ms960651_1996 if ms960651_1996>=0;
   
replace often_museum1998 = ms981b10_1998 if ms981b10_1998>=0;   
replace often_museum1998 = ms981c09_1998 if ms981c09_1998>=0;
replace often_museum1998 = ms981d08_1998 if ms981d08_1998>=0;   

replace often_museum2000 = ms1_a10_2000 if ms1_a10_2000>=0;   
replace often_museum2000 = ms1_b09_2000 if ms1_b09_2000>=0;
replace often_museum2000 = ms1_c08_2000 if ms1_c08_2000>=0;

replace often_museum2002 = home_b10_2002 if home_b10_2002>=0;   
replace often_museum2002 = home_c09_2002 if home_c09_2002>=0;
replace often_museum2002 = home_d08_2002 if home_d08_2002>=0;   

replace often_museum2004 = home_b10_2004 if home_b10_2004>=0;   
replace often_museum2004 = home_c09_2004 if home_c09_2004>=0;
replace often_museum2004 = home_d08_2004 if home_d08_2004>=0;   
 
replace often_museum2006 = ms_home_b10_2006 if ms_home_b10_2006>=0;   
replace often_museum2006 = ms_home_c09_2006 if ms_home_c09_2006>=0;
replace often_museum2006 = ms_home_d08_2006 if ms_home_d08_2006>=0;

replace often_museum2008 = ms_home_b10_2008 if ms_home_b10_2008>=0;   
replace often_museum2008 = ms_home_c09_2008 if ms_home_c09_2008>=0;
replace often_museum2008 = ms_home_d08_2008 if ms_home_d08_2008>=0;

replace often_museum2010 = ms_home_b10_2010 if ms_home_b10_2010>=0;   
replace often_museum2010 = ms_home_c09_2010 if ms_home_c09_2010>=0;
replace often_museum2010 = ms_home_d08_2010 if ms_home_d08_2010>=0;

replace often_museum2012 = ms_home_b10_2012 if ms_home_b10_2012>=0;   
replace often_museum2012 = ms_home_c09_2012 if ms_home_c09_2012>=0;
replace often_museum2012 = ms_home_d08_2012 if ms_home_d08_2012>=0;
  



**************;
*Number of times child is praised;
**************; 
 
*No info about it in 1986;
gen often_praised1988=-7;
gen often_praised1990=-7;
gen often_praised1992=-7;
gen often_praised1994=-7;
gen often_praised1996=-7;
gen often_praised1998=-7;
gen often_praised2000=-7;
gen often_praised2002=-7;
gen often_praised2004=-7;
gen often_praised2006=-7;
gen often_praised2008=-7;
gen often_praised2010=-7;
gen often_praised2012=-7;




replace often_praised1988 = ms880432_1988 if ms880432_1988>=0 & ms880432_1988<=20;   
replace often_praised1988 = ms880524_1988 if ms880524_1988>=0 & ms880524_1988<=20;
  
replace often_praised1990 = ms900565_1990 if ms900565_1990>=0 & ms900565_1990<=20;   
replace often_praised1990 = ms900741_1990 if ms900741_1990>=0 & ms900741_1990<=20;   

replace often_praised1992 = ms920561_1992 if ms920561_1992>=0 & ms920561_1992<=20;   
replace often_praised1992 = ms920737_1992 if ms920737_1992>=0 & ms920737_1992<=20;   

replace often_praised1994 = ms940617_1994 if ms940617_1994>=0 & ms940617_1994<=20;   
replace often_praised1994 = ms940837_1994 if ms940837_1994>=0 & ms940837_1994<=20;   

replace often_praised1996 = ms960617_1996 if ms960617_1996>=0 & ms960617_1996<=20;   
replace often_praised1996 = ms960837_1996 if ms960837_1996>=0 & ms960837_1996<=20;   

replace often_praised1998 = ms981c24d_1998 if ms981c24d_1998>=0 & ms981c24d_1998<=20;   
replace often_praised1998 = ms981d23d_1998 if ms981d23d_1998>=0 & ms981d23d_1998<=20;   

replace often_praised2000 = ms1_b24d_2000 if ms1_b24d_2000>=0 & ms1_b24d_2000<=20;   
replace often_praised2000 = ms1_c23d_2000 if ms1_c23d_2000>=0 & ms1_c23d_2000<=20;   

replace often_praised2002 = home_c24d_2002 if home_c24d_2002>=0 & home_c24d_2002<=20;   
replace often_praised2002 = home_d23d_2002 if home_d23d_2002>=0 & home_d23d_2002<=20;   

replace often_praised2004 = home_c24d_2004 if home_c24d_2004>=0 & home_c24d_2004<=20;   
replace often_praised2004 = home_d23d_2004 if home_d23d_2004>=0 & home_d23d_2004<=20;   

replace often_praised2006 = ms_home_c24d_2006 if ms_home_c24d_2006>=0 & ms_home_c24d_2006<=20;   
replace often_praised2006 = ms_home_d23d_2006 if ms_home_d23d_2006>=0 & ms_home_d23d_2006<=20;   

replace often_praised2008 = ms_home_c24d_2008 if ms_home_c24d_2008>=0 & ms_home_c24d_2008<=20;   
replace often_praised2008 = ms_home_d23d_2008 if ms_home_d23d_2008>=0 & ms_home_d23d_2008<=20;   


replace often_praised2010 = ms_home_c24d_2010 if ms_home_c24d_2010>=0 & ms_home_c24d_2010<=20;   
replace often_praised2010 = ms_home_d23d_2010 if ms_home_d23d_2010>=0 & ms_home_d23d_2010<=20;   


replace often_praised2012 = ms_home_c24d_2012 if ms_home_c24d_2012>=0 & ms_home_c24d_2012<=20;   
replace often_praised2012 = ms_home_d23d_2012 if ms_home_d23d_2012>=0 & ms_home_d23d_2012<=20;   




**************;
*Number of times said positive things;
**************; 
 
*No info about it in 1986;


gen often_positive1988=-7;
gen often_positive1990=-7;
gen often_positive1992=-7;
gen often_positive1994=-7;
gen often_positive1996=-7;
gen often_positive1998=-7;
gen often_positive2000=-7;
gen often_positive2002=-7;
gen often_positive2004=-7;
gen often_positive2006=-7;
gen often_positive2008=-7;
gen often_positive2010=-7;
gen often_positive2012=-7;


replace often_positive1988 = ms880434_1988 if ms880434_1988>=0 & ms880434_1988<=20;   
replace often_positive1988 = ms880526_1988 if ms880526_1988>=0 & ms880526_1988<=20;

replace often_positive1990 = ms900567_1990 if ms900567_1990>=0 & ms900567_1990<=20;   
replace often_positive1990 = ms900743_1990 if ms900743_1990>=0 & ms900743_1990<=20;

replace often_positive1992 = ms920569_1992 if ms920569_1992>=0 & ms920569_1992<=20;   
replace often_positive1992 = ms920745_1992 if ms920745_1992>=0 & ms920745_1992<=20;

replace often_positive1994 = ms940625_1994 if ms940625_1994>=0 & ms940625_1994<=20;   
replace often_positive1994 = ms940845_1994 if ms940845_1994>=0 & ms940845_1994<=20;

replace often_positive1996 = ms960625_1996 if ms960625_1996>=0 & ms960625_1996<=20;   
replace often_positive1996 = ms960845_1996 if ms960845_1996>=0 & ms960845_1996<=20;

replace often_positive1998 = ms981c24h_1998 if ms981c24h_1998>=0 & ms981c24h_1998<=20;   
replace often_positive1998 = ms981d23h_1998 if ms981d23h_1998>=0 & ms981d23h_1998<=20;

replace often_positive2000 = ms1_b24h_2000 if ms1_b24h_2000>=0 & ms1_b24h_2000<=20;   
replace often_positive2000 = ms1_c23h_2000 if ms1_c23h_2000>=0 & ms1_c23h_2000<=20;

replace often_positive2002 = home_c24h_2002 if home_c24h_2002>=0 & home_c24h_2002<=20;   
replace often_positive2002 = home_d23h_2002 if home_d23h_2002>=0 & home_d23h_2002<=20;

replace often_positive2004 = home_c24h_2004 if home_c24h_2004>=0 & home_c24h_2004<=20;   
replace often_positive2004 = home_d23h_2004 if home_d23h_2004>=0 & home_d23h_2004<=20;

replace often_positive2006 = ms_home_c24h_2006 if ms_home_c24h_2006>=0 & ms_home_c24h_2006<=20;   
replace often_positive2006 = ms_home_d23h_2006 if ms_home_d23h_2006>=0 & ms_home_d23h_2006<=20;

replace often_positive2008 = ms_home_c24h_2008 if ms_home_c24h_2008>=0 & ms_home_c24h_2008<=20;   
replace often_positive2008 = ms_home_d23h_2008 if ms_home_d23h_2008>=0 & ms_home_d23h_2008<=20;

replace often_positive2010 = ms_home_c24h_2010 if ms_home_c24h_2010>=0 & ms_home_c24h_2010<=20;   
replace often_positive2010 = ms_home_d23h_2010 if ms_home_d23h_2010>=0 & ms_home_d23h_2010<=20;

replace often_positive2012 = ms_home_c24h_2012 if ms_home_c24h_2012>=0 & ms_home_c24h_2012<=20;   
replace often_positive2012 = ms_home_d23h_2012 if ms_home_d23h_2012>=0 & ms_home_d23h_2012<=20;   
		   

		   
**************;
*Often family sees friends;
**************;
gen often_see_family_friends1986=-7;
gen often_see_family_friends1988=-7;
gen often_see_family_friends1990=-7;
gen often_see_family_friends1992=-7;
gen often_see_family_friends1994=-7;
gen often_see_family_friends1996=-7;
gen often_see_family_friends1998=-7;
gen often_see_family_friends2000=-7;
gen often_see_family_friends2002=-7;
gen often_see_family_friends2004=-7;
gen often_see_family_friends2006=-7;
gen often_see_family_friends2008=-7;
gen often_see_family_friends2010=-7;
gen often_see_family_friends2012=-7;


*There is only one variable in 1986 for often see family friends;
replace often_see_family_friends1986 = ms860226_1986 if ms860226_1986>=0; 

replace often_see_family_friends1988 = ms880351_1988 if ms880351_1988>=0;   
replace often_see_family_friends1988 = ms880450_1988 if ms880450_1988>=0;

replace often_see_family_friends1990 = ms900455_1990 if ms900455_1990>=0;   
replace often_see_family_friends1990 = ms900637_1990 if ms900637_1990>=0;

replace often_see_family_friends1992 = ms920455_1992 if ms920455_1992>=0;   
replace often_see_family_friends1992 = ms920637_1992 if ms920637_1992>=0 & ms920637_1992<=5;

replace often_see_family_friends1994 = ms940463_1994 if ms940463_1994>=0;   
replace often_see_family_friends1994 = ms940655_1994 if ms940655_1994>=0;

replace often_see_family_friends1996 = ms960461_1996 if ms960461_1996>=0;   
replace often_see_family_friends1996 = ms960655_1996 if ms960655_1996>=0;

replace often_see_family_friends1998 = ms981c11_1998 if ms981c11_1998>=0;   
replace often_see_family_friends1998 = ms981d10_1998 if ms981d10_1998>=0;

replace often_see_family_friends2000 = ms1_b11_2000 if ms1_b11_2000>=0;   
replace often_see_family_friends2000 = ms1_c10_2000 if ms1_c10_2000>=0;

replace often_see_family_friends2002 = home_c11_2002 if home_c11_2002>=0;   
replace often_see_family_friends2002 = home_d10_2002 if home_d10_2002>=0;

replace often_see_family_friends2004 = home_c11_2004 if home_c11_2004>=0;   
replace often_see_family_friends2004 = home_d10_2004 if home_d10_2004>=0;

replace often_see_family_friends2006 = ms_home_c11_2006 if ms_home_c11_2006>=0;   
replace often_see_family_friends2006 = ms_home_d10_2006 if ms_home_d10_2006>=0;

replace  often_see_family_friends2008 = ms_home_c11_2008 if ms_home_c11_2008>=0;   
replace often_see_family_friends2008 = ms_home_d10_2008 if ms_home_d10_2008>=0;

replace often_see_family_friends2010 = ms_home_c11_2010 if ms_home_c11_2010>=0;   
replace often_see_family_friends2010 = ms_home_d10_2010 if ms_home_d10_2010>=0;

replace often_see_family_friends2012 = ms_home_c11_2012 if ms_home_c11_2012>=0;   
replace often_see_family_friends2012 = ms_home_d10_2012 if ms_home_d10_2012>=0;           


*OTHER INVESTMENTS;


**************;
*Often child get special lessions/activities;
**************;
gen has_lessons1986=-7;
gen has_lessons1988=-7;
gen has_lessons1990=-7;
gen has_lessons1992=-7;
gen has_lessons1994=-7;
gen has_lessons1996=-7;
gen has_lessons1998=-7;
gen has_lessons2000=-7;
gen has_lessons2002=-7;
gen has_lessons2004=-7;
gen has_lessons2006=-7;
gen has_lessons2008=-7;
gen has_lessons2010=-7;
gen has_lessons2012=-7;

*There is only one variable in 1986 for often has lessons;
replace has_lessons1986 = ms860223_1986 if ms860223_1986>=0; 

replace has_lessons1988 = ms880348_1988 if ms880348_1988>=0;   
replace has_lessons1988 = ms880447_1988 if ms880447_1988>=0;

replace has_lessons1990 = ms900449_1990 if ms900449_1990>=0;   
replace has_lessons1990 = ms900631_1990 if ms900631_1990>=0;

replace has_lessons1992 = ms920449_1992 if ms920449_1992>=0;   
replace has_lessons1992 = ms920631_1992 if ms920631_1992>=0 & ms920631_1992<=1;

replace has_lessons1994 = ms940457_1994 if ms940457_1994>=0;   
replace has_lessons1994 = ms940649_1994 if ms940649_1994>=0;

replace has_lessons1996 = ms960455_1996 if ms960455_1996>=0;   
replace has_lessons1996 = ms960649_1996 if ms960649_1996>=0;

replace has_lessons1998 = ms981c08_1998 if ms981c08_1998>=0;   
replace has_lessons1998 = ms981d07_1998 if ms981d07_1998>=0;

replace has_lessons2000 = ms1_b08_2000 if ms1_b08_2000>=0;   
replace has_lessons2000 = ms1_c07_2000 if ms1_c07_2000>=0;

replace has_lessons2002 = home_c08_2002 if home_c08_2002>=0;   
replace has_lessons2002 = home_d07_2002 if home_d07_2002>=0;

replace has_lessons2004 = home_c08_2004 if home_c08_2004>=0;   
replace has_lessons2004 = home_d07_2004 if home_d07_2004>=0;

replace has_lessons2006 = ms_home_c08_2006 if ms_home_c08_2006>=0;   
replace has_lessons2006 = ms_home_d07_2006 if ms_home_d07_2006>=0;

replace has_lessons2008 = ms_home_c08_2008 if ms_home_c08_2008>=0;   
replace has_lessons2008 = ms_home_d07_2008 if ms_home_d07_2008>=0;

replace has_lessons2010 = ms_home_c08_2010 if ms_home_c08_2010>=0;   
replace has_lessons2010 = ms_home_d07_2010 if ms_home_d07_2010>=0;

replace has_lessons2012 = ms_home_c08_2012 if ms_home_c08_2012>=0;   
replace has_lessons2012 = ms_home_d07_2012 if ms_home_d07_2012>=0;    



**************;
*Often child taken to performances;
**************;

gen attend_mus_perform1986=-7;
gen attend_mus_perform1988=-7;
gen attend_mus_perform1990=-7;
gen attend_mus_perform1992=-7;
gen attend_mus_perform1994=-7;
gen attend_mus_perform1996=-7;
gen attend_mus_perform1998=-7;
gen attend_mus_perform2000=-7;
gen attend_mus_perform2002=-7;
gen attend_mus_perform2004=-7;
gen attend_mus_perform2006=-7;
gen attend_mus_perform2008=-7;
gen attend_mus_perform2010=-7;
gen attend_mus_perform2012=-7;


*There is only one variable in 1986 for often attends musical performances;
replace attend_mus_perform1986 = ms860225_1986 if ms860225_1986>0; 

replace attend_mus_perform1988 = ms880350_1988 if ms880350_1988>0;   
replace attend_mus_perform1988 = ms880449_1988 if ms880449_1988>0;

replace attend_mus_perform1990 = ms900453_1990 if ms900453_1990>0;   
replace attend_mus_perform1990 = ms900635_1990 if ms900635_1990>0;

replace attend_mus_perform1992 = ms920453_1992 if ms920453_1992>0;   
replace attend_mus_perform1992 = ms920635_1992 if ms920635_1992>0;

replace attend_mus_perform1994 = ms940461_1994 if ms940461_1994>0;   
replace attend_mus_perform1994 = ms940653_1994 if ms940653_1994>0;

replace attend_mus_perform1996 = ms960459_1996 if ms960459_1996>0;   
replace attend_mus_perform1996 = ms960653_1996 if ms960653_1996>0;

replace attend_mus_perform1998 = ms981c10_1998 if ms981c10_1998>0;   
replace attend_mus_perform1998 = ms981d09_1998 if ms981d09_1998>0;

replace attend_mus_perform2000 = ms1_b10_2000 if ms1_b10_2000>0;   
replace attend_mus_perform2000 = ms1_c09_2000 if ms1_c09_2000>0;

replace attend_mus_perform2002 = home_c10_2002 if home_c10_2002>0;   
replace attend_mus_perform2002 = home_d09_2002 if home_d09_2002>0;

replace attend_mus_perform2004 = home_c10_2004 if home_c10_2004>0;   
replace attend_mus_perform2004 = home_d09_2004 if home_d09_2004>0;

replace attend_mus_perform2006 = ms_home_c10_2006 if ms_home_c10_2006>0;   
replace attend_mus_perform2006 = ms_home_d09_2006 if ms_home_d09_2006>0;

replace attend_mus_perform2008 = ms_home_c10_2008 if ms_home_c10_2008>0;   
replace attend_mus_perform2008 = ms_home_d09_2008 if ms_home_d09_2008>0;

replace attend_mus_perform2010 = ms_home_c10_2010 if ms_home_c10_2010>0;   
replace attend_mus_perform2010 = ms_home_d09_2010 if ms_home_d09_2010>0;

replace attend_mus_perform2012 = ms_home_c10_2012 if ms_home_c10_2012>0;   
replace attend_mus_perform2012 = ms_home_d09_2012 if ms_home_d09_2012>0;


***************************************************************************************;
*re-shape dataset
***************************************************************************************;


keep 
child_id_nlsy mom_id_nlsy child_race child_sex child_ybirth child_birth_order
math* recog* comp* ppvt*
actvty* predct* fear* affect* comply* insecur* sociab* moto* anti* anx* negatv*
head* hypr* dep* peer*
digit*
diffic* friend* body* loca*
weight_atbirth* gest_length*
often_house* number_books* number_soft_toys* number_push_toys* number_magazines* has_tape_cd* 
has_musical_instrument* has_newspaper* often_mom_reads* often_eats_mom* 
often_mom_talks* often_museum* often_praised* often_positive* often_see_family_friends*
has_lessons* attend_mus_perform*
se1* se2* se3* se4* se5* se6* se8* se9* se10* 
rotter1* rotter2* rotter3* rotter4* 
asvab2* asvab3* asvab4* asvab5* asvab6* asvab8* 
faminc*
education* 
real_wage_income* hour_wage* hours*
mom_school* mom_marital* mom_age* mom_family_size*
wage_children*
;


reshape long 
math@ recog@ comp@ ppvt@
actvty@ predct@ fear@ affect@ comply@ insecur@ negatv@
sociab@ moto@ anti@ anx@ 
head@ hypr@ dep@ peer@
digit@
diffic@ friend@ body@ loca@
weight_atbirth@ gest_length@
often_house@ number_books@ number_soft_toys@ number_push_toys@ number_magazines@ has_tape_cd@ 
has_musical_instrument@ has_newspaper@ often_mom_reads@ often_eats_mom@ 
often_mom_talks@ often_museum@ often_praised@ often_positive@ often_see_family_friends@
has_lessons@ attend_mus_perform@
se1@ se2@ se3@ se4@ se5@ se6@ se8@ se9@ se10@ 
rotter1@ rotter2@ rotter3@ rotter4@ 
asvab2@ asvab3@ asvab4@ asvab5@ asvab6@ asvab8@
faminc@
education@
real_wage_income@ hour_wage@ hours@
mom_school@ mom_marital@ mom_age@ mom_family_size@
wage_children@
,i( child_id_nlsy ) j(year);


******************************************************************************;
*replace missing codes with dots;
******************************************************************************;

local all_measures = "math recog comp ppvt
actvty predct fear affect comply insecur sociab moto anti anx negatv
head hypr dep peer
digit
diffic friend body loca 
weight_atbirth number_books number_soft_toys number_push_toys number_magazines has_tape_cd 
has_musical_instrument";
*negative values for all measures indicate missing;
foreach var of local all_measures {;
replace `var' = . if `var' < 0;
};


local all_measures2 = "
  has_newspaper  often_mom_reads often_eats_mom 
often_mom_talks often_museum often_praised often_positive often_see_family_friends
has_lessons attend_mus_perform often_house
se1 se2 se3 se4 se5 se6 se8 se9 se10 
rotter1 rotter2 rotter3 rotter4";

foreach var of local all_measures2 {;
replace `var' = . if `var' < 0;
};


local all_measures3 = " 
asvab2 asvab3 asvab4 asvab5 asvab6 asvab8 
faminc education gest_length real_wage_income hour_wage hours
wage_children
";

foreach var of local all_measures3 {;
replace `var' = . if `var' < 0;
};


******************************************************************************;
*reverse ordering for "negative" measures;
******************************************************************************;

foreach var of varlist anti anx head hypr dep peer often_eats_mom often_mom_talks
 insecur negatv fear diffic se1 se2 se4 se6{;
egen temp1 = max(`var');
gen temp2 = -1*(`var' - temp1);
replace `var' = temp2;
drop temp*;
};


*e.g.;
*1,2,3,4,5;
*1-5 = -4;
*2-5 = -3;
*3-5 = -2;
*4-5 = -1;
*5-5 = 0;
     

	 
******************************************************************************;
*keep selected variables
******************************************************************************;	 
	 
keep child_id_nlsy mom_id_nlsy year child_ybirth  gest_length education child_sex child_birth_order often_museum math recog comp ppvt actvty predct 
fear affect comply insecur negatv sociab moto anti anx head hypr dep peer digit 
diffic friend body loca weight_atbirth often_house number_books number_soft_toys number_push_toys 
number_magazines has_tape_cd has_musical_instrument has_newspaper often_mom_reads 
often_eats_mom often_mom_talks often_praised often_positive often_see_family_friends 
has_lessons attend_mus_perform se1 se2 se3 se4 se5 se6 se8 se9 se10 rotter1 rotter2 
rotter3 rotter4 asvab2 asvab3 asvab4 asvab5 asvab6 asvab8 faminc child_race
hours real_wage_income hour_wage education
mom_school mom_marital mom_age mom_family_size
wage_children
;

******************************************************************************;
*generate new variables;
******************************************************************************;

gen child_age = year - child_ybirth;

******************************************************************************;
*rename some variables to match CHS variable names
******************************************************************************;

rename actvty tempA;
rename predct tempB;
rename fear tempC;
rename affect tempD;
rename comply tempE;
rename insecur tempF;
rename sociab tempG;
rename negatv tempH;
rename diffic tempI;
rename friend tempJ;

*
TemperamentA/Activity Raw Score
TemperamentB/Predictability Raw Score
TemperamentC/Fearfulness Raw Score
TemperamentD/Positive Affect Raw Score
TemperamentE/Compliance Raw Score
TemperamentF/Insecure Attachment Raw Score
TemperamentG/Sociability Raw Score
TemperamentH/Neg Hedonic Tone Raw Score
TemperamentI/ Difficulty Raw Score
TemperamentJ/ Friendliness Raw Score
;

rename anti bpiA;
rename anx bpiB; 
rename head bpiC; 
rename hypr bpiD; 
rename peer bpiE;

*
Behavior Problem Index/ Antisocial Raw Score
Behavior Problem Index/ Anxiety Raw Score
Behavior Problem Index/ Headstrong Raw Score
Behavior Problem Index/ Hyperactive Raw Score
Behavior Problem Index/ Conflict Raw Score
;


******************************************************************************;
*compress, sort, order
******************************************************************************;


compress;

sort mom_id_nlsy child_id_nlsy year;
order 
mom_id_nlsy child_id_nlsy year child_age mom_age
child_birth_order child_race child_sex child_ybirth 
mom_school mom_marital mom_family_size real_wage_income faminc hour_wage
;

